<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <link rel="icon" type="image/x-icon" href="/favicon.ico">
        <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
        <title>upload</title>
        <script type='text/javascript'>
             window.Laravel = <?php echo json_encode([
                'csrfToken' => csrf_token(),
            ]); ?>
        </script>
    </head>
    <body>
     <form id= "uploadForm" enctype="multipart/form-data" >
            <p >上传文件： <input type="file" name="pic"/></ p>
                <input type="hidden" name="_token" value="{{csrf_token()}}">
            <input type="button" value="上传" onclick="doUpload()" />
    </form>
    <div class="show-div" style="display: none;">
    上传的图片：
      <img class="show-img" src="" >
    </div>
</html>

<script>
    function doUpload() {
        var formData = new FormData($( "#uploadForm" )[0]);
        formData.append("CODE","123456");  //自定义参数传递
        $.ajax({
            url:  "/createImages",
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                console.log(data);
                if(data){
                    $('.show-img').attr('src',data.path);
                    $('.show-div').attr('style','');
                }
            },
            error: function (data) {
                console.log(data);
            }
        });
    }

</script>